package tk.mynoteapp.dev.demo21.templatemethod.right;

import tk.mynoteapp.dev.demo21.templatemethod.Db;
import tk.mynoteapp.dev.demo21.templatemethod.Item;

import java.math.BigDecimal;

// VP用户购物车
public class VipUserCart extends NormalUserCart {

    @Override
    void processCouponPrice(long userId, Item item) {
        // VIP购买两件以上相同商品，第三件开始享受一定折扣
        if (item.getQuantity() > 2) {
            item.setCouponPrice(item.getPrice()
                    // 10%
                    .multiply(BigDecimal.valueOf(100 - Db.getUserCouponPercent(userId)).divide(new BigDecimal("100")))
                    .multiply(BigDecimal.valueOf(item.getQuantity() - 2)));
        } else {
            // 无优惠
            item.setCouponPrice(BigDecimal.ZERO);
        }
    }
}
